package com.zy.homework1128;

import java.util.*;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/11/28 9:36
 **/
public class TestStr2 {
    private Map<String,Integer> map = new HashMap<String,Integer>();
    public static void main(String[] args) {
        TestStr2 testStr = new TestStr2();

        String str = "Integer包装类的public static int parseInt(String s)：可以将由“数字”字符组成的字符串转换为整型。\n";
        String[] strAry = str.split(" ");//原数据
        for (int i = 0; i < strAry.length; i++) {
            testStr.addNum(strAry[i]);//统计数量
        }
        testStr.showMap();
    }

    public void addNum(String str){
        Integer i = map.get(str);
        if(null == i){
            map.put(str,1);
        }else{
            map.put(str,1 + i);
        }
    }
    public  void showMap(){
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry entry:entries
             ) {
            Object key = entry.getKey();
            Object value = entry.getValue();
            System.out.println(key + ":" +value);
        }
    }

}
